﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

public partial class UserControl_tin_chi_tiet : System.Web.UI.UserControl
{
    protected int intTieuDe = 0;
    protected string strTieuDe = "";
    protected string strNoiDung = "";
    protected string strMoTa = "";
    protected string strNgayTao = "";
    protected string strSoluotxem = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        xGetParam();
    }
    /// <summary>
    /// Lấy mã tin tức trên URL
    /// Author:ThuaNH
    /// Create date:11/11/2013
    /// </summary>
    private void xGetParam()
    {
        string strTenPhong = clsCommon.fncGetRoute(this.Page, "param1");
        string[] strLstKey = strTenPhong.Split('-');
        string strMaTin = strLstKey[strLstKey.Length - 1];
        xGetDetail(OsPortal.oStringHelper.fncCnvNullToInt(strMaTin));
        intTieuDe = OsPortal.oStringHelper.fncCnvNullToInt(strMaTin);
    }

    /// <summary>
    /// Lấy chi tiết tin
    /// Author: ThuanNH
    /// Create: 11/11/2013
    /// </summary>
    /// <param name="iTI_ID">Mã tin</param>
    private void xGetDetail(int iTI_ID)
    {
        DataTable dt = clsTinDang.fncTinDang_DETAIL(iTI_ID, "");
        if (dt == null) return;
        if (dt.Rows.Count <= 0) return;
        strTieuDe = dt.Rows[0]["TI_TIEUDE"].ToString();
        strNgayTao =  String.Format("{0:dd/MM/yyyy}",Convert.ToDateTime(dt.Rows[0]["TI_NGAYTAO"].ToString()));
        strSoluotxem = dt.Rows[0]["TI_SOLUOTXEM"].ToString();
        strMoTa = dt.Rows[0]["TI_MOTA"].ToString();
        strNoiDung = dt.Rows[0]["TI_NOIDUNG"].ToString();
        idHD.Value = Convert.ToString(iTI_ID);

        //if (iTI_ID == 32) { 
        //    string pageurl = "http://nghikhac.com/lich-khai-giang/18-bi-quyet-kinh-doanh-dot-pha-56";
        //    //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "null", "window.open('" + pageurl + "','_newtab')", true);
        //    Page.ClientScript.RegisterStartupScript(this.GetType(), "openwindow", "window.open('" + pageurl + "','','height=200,width=300')", true);
        //}

        this.Page.Title = strTieuDe;
        this.Page.MetaDescription = strMoTa;

        // Tag meta title + des Facebook
        HtmlMeta tag = new HtmlMeta();
        tag.Attributes.Add("property", "og:title");
        tag.Content = strTieuDe;
        Page.Header.Controls.Add(tag);

        HtmlMeta tag2 = new HtmlMeta();
        tag2.Attributes.Add("property", "og:description");
        strMoTa = dt.Rows[0]["TI_MOTA"].ToString();
        strMoTa = strMoTa.Replace("&lt;", "<");
        strMoTa = OsPortal.oStringHelper.ClearTagHTML(HttpUtility.HtmlDecode(strMoTa));
        tag2.Content = strMoTa;
        
        Page.Header.Controls.Add(tag2);
        // END Tag meta title + des Facebook
    }
}
